package com.suixingfu.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.suixingfu.utils.Des;
import com.suixingfu.utils.Md5;

@Controller
public class LoginController {

	//登录页面
	@RequestMapping("/login")
	public String login() throws IOException{
		return "view/login/login";
	}
	
	//点击登录
	@RequestMapping(value="/loginHandler",method=RequestMethod.POST)
	@ResponseBody
	public int loginHandler(@RequestParam("username")String username,@RequestParam("psw")String psw,HttpSession session){
		String uname=new Des().strDec(username, "9", "9", "9");//解密用户名
		String password=Md5.getMD5(("20160909S.x.f").getBytes());//md5加密密码
		if(uname.equals("suixingfu")&&psw.equals(password)){//用户名和密码暂时固定
			session.setAttribute("uname", uname);
			//跳转到单笔付款申请
//			return "forward:/danbifukuan";
			return 1;
			
		}else{
			System.out.println("login,uname="+username+",psw="+psw);
//			return "forward:/login";
			return 0;
		}

	}

}
